<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

<xsl:template match="selectform">
	<div class="sel_box">
		<form method="post">
			<xsl:attribute name="action"><xsl:apply-templates select="action"/></xsl:attribute>
			<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
			<xsl:for-each select="fld">
				<xsl:call-template name="flds"><xsl:with-param name="isConfirm">no</xsl:with-param></xsl:call-template>
			</xsl:for-each>
			<input type="button" value="GO" class="sel_btn">
				<xsl:attribute name="onclick">javascript:<xsl:value-of select="@name"/>.submit()</xsl:attribute>
			</input>
		</form>
	</div>              
</xsl:template>

<xsl:template match="grpform">
	<div class="grp_box">
		<form method="post">
			<xsl:attribute name="action"><xsl:apply-templates select="action"/></xsl:attribute>
			<xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>
			<xsl:call-template name="grpform-hidden"/>
			<div class="grp_box_flt">
				<table cellpadding="0" cellspacing="0" class="flt_table">
					<xsl:apply-templates select="filters"/>
				</table>
			</div>
			<div class="grp_box_data">
				<table cellpadding="0" cellspacing="0" class="grp_table">
				  	<xsl:apply-templates select="head"/>
					<xsl:apply-templates select="items"/>
			        <xsl:apply-templates select="head"/>
				</table>
			</div>
		</form>
	</div>              
</xsl:template>

<xsl:template match="grpform/title">
</xsl:template>

<xsl:template match="action">
	<xsl:call-template name="grpform-action"/>
</xsl:template>

<xsl:template match="grpform/filters">
	<tr><xsl:apply-templates select="filter"/></tr>
</xsl:template>

<xsl:template match="grpform/filters/filter">
	<xsl:variable name="thisname"><xsl:value-of select="ancestor::grpform/@name"/></xsl:variable>
	<xsl:variable name="xslfilt"><xsl:value-of select="ancestor::grpform/@xslfilter"/></xsl:variable>
	<xsl:choose>
		<xsl:when test="count(subobjs/subwf_obj)&gt;1">
			<td>
				<span class="flt_drop"><xsl:call-template name="select_drop"/></span>
			</td>
			<td class="flt_btn">
				<input type="button" value="GO" class="grp_btn">
					<xsl:attribute name="onclick">
						<xsl:choose>
							<xsl:when test="@name = $xslfilt">
								<xsl:text>javascript:x_grp.Filter(</xsl:text>
								<xsl:value-of select="$thisname"/>
								<xsl:text>, '</xsl:text>
								<xsl:apply-templates select="ancestor::grpform/action"/>
								<xsl:text>');</xsl:text>
							</xsl:when>
							<xsl:otherwise>
								<xsl:text>javascript:x_grp.Goto('filter',</xsl:text>
								<xsl:value-of select="$thisname"/>
								<xsl:text>);</xsl:text>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:attribute>
				</input>
			</td>
		</xsl:when>
		<xsl:when test="count(subobjs/subwf_obj)=1">
			<td>
				<span class="flt_drop"><xsl:call-template name="input_notext"/></span>
			</td>
		</xsl:when>
		<xsl:otherwise>
			<td>
				<span class="flt_drop">
					<xsl:call-template name="select_drop">
						<xsl:with-param name="confirm"><xsl:text>yes</xsl:text></xsl:with-param>
					</xsl:call-template>
				</span>
			</td>
		</xsl:otherwise>
	</xsl:choose>
	
</xsl:template>

<xsl:template match="grpform/head">
	<tr class="grp_row_head">
		<xsl:apply-templates select="heading[not(@visible='no')]"/>
	</tr>
</xsl:template>

<xsl:template match="grpform/head/heading">
	<xsl:variable name="thisname"><xsl:value-of select="ancestor::grpform/@name"/></xsl:variable>
	<th>
		<xsl:attribute name="class">
			<xsl:choose>
				<xsl:when test="position() = 1"></xsl:when>
				<xsl:otherwise>grp_cell_hd</xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
		<xsl:if test="@size"><xsl:attribute name="width"><xsl:value-of select="@size"/></xsl:attribute></xsl:if>
		<!--
		<xsl:attribute name="width">
			<xsl:choose>
				<xsl:when test="@size"><xsl:value-of select="@size"/></xsl:when>
				<xsl:otherwise><xsl:text>*</xsl:text></xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
		-->
		<xsl:if test="@size"><xsl:attribute name="width"><xsl:value-of select="@size"/></xsl:attribute></xsl:if>
		<xsl:choose>
			<xsl:when test="@type='action-drop'">
				<xsl:attribute name="class">grp_cell_hdact</xsl:attribute>
				<xsl:choose>
					<xsl:when test="action">
						<input type="button" class="grp_btn">
							<xsl:attribute name="value"><xsl:value-of select="action"/></xsl:attribute>
							<xsl:attribute name="onclick">
								<xsl:text>javascript:x_grp.Url('</xsl:text>
								<xsl:apply-templates select="action"/>
								<xsl:text>');</xsl:text>
							</xsl:attribute>
						</input>
					</xsl:when>
					<xsl:otherwise></xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:when test="@sort">
				<span class="grp_text_hd">
					<a title="Click to sort by column" class="grp_lnk">
						<xsl:attribute name="href">
							<!--NB: x_grp.Sort is a js function on the client to submit the form with the hidden field set with the sort order
									x_grp.Order is used for xsl sorts, rather than getting sorted data from the back-end -->
							<xsl:choose>
								<xsl:when test="ancestor::grpform/@xslsort='yes'"><xsl:text>javascript:x_grp.Order('</xsl:text></xsl:when>
								<xsl:otherwise><xsl:text>javascript:x_grp.Sort('</xsl:text></xsl:otherwise>
							</xsl:choose>
							<xsl:value-of select="@sort"/>
							<xsl:text>', </xsl:text>
							<xsl:value-of select="$thisname"/>
							<xsl:text>, '</xsl:text>
							<xsl:apply-templates select="ancestor::grpform/action"/>
							<xsl:text>');</xsl:text>
						</xsl:attribute>
						<xsl:value-of select="child::text()"/>
					</a>
				</span>
			</xsl:when>
			<xsl:when test="@type='action'">
				<span class="grp_text_hd"><xsl:value-of select="child::text()"/></span>
			</xsl:when>
			<xsl:otherwise>
				<span class="grp_text_hd"><xsl:apply-templates/></span>
			</xsl:otherwise>
		</xsl:choose>
	</th>
</xsl:template>

<xsl:template match="grpform/items">
	<xsl:variable name="xslfilter"><xsl:value-of select="ancestor::grpform/@xslfilter"/></xsl:variable>
	<xsl:variable name="filteratt"><xsl:value-of select="ancestor::grpform/@filteratt"/></xsl:variable>
	<xsl:variable name="filterval"><xsl:value-of select="ancestor::grpform/filters/filter[@name=$xslfilter]/value"/></xsl:variable>
	<xsl:variable name="sortorder"><xsl:value-of select="ancestor::grpform/@sortorder"/></xsl:variable>
	<xsl:comment>xslfilter: '<xsl:value-of select="$xslfilter"/>'</xsl:comment>
	<xsl:comment>filteratt: '<xsl:value-of select="$filteratt"/>'</xsl:comment>
	<xsl:comment>filterval: '<xsl:value-of select="$filterval"/>'</xsl:comment>
	<xsl:comment>sortorder: '<xsl:value-of select="$sortorder"/>'</xsl:comment>
	<xsl:comment>dateorder: '<xsl:value-of select="ancestor::grpform/head/heading[@sort=$sortorder]/@date"/>'</xsl:comment>
	<xsl:choose>
		<xsl:when test="nodata"><xsl:apply-templates select="nodata"/></xsl:when>
		<xsl:when test="$filterval != '' and $filterval != '0'">
			<xsl:choose>
				<xsl:when test="$sortorder != ''">
					<xsl:choose>
						<xsl:when test="ancestor::grpform/head/heading[@sort=$sortorder]/@number='yes'">
							<xsl:call-template name="grpform-items">
								<xsl:with-param name="filtatt" select="$filteratt"/>
								<xsl:with-param name="filtval" select="$filterval"/>
								<xsl:with-param name="sorttyp">order-number</xsl:with-param>
								<xsl:with-param name="sortord" select="$sortorder"/>
							</xsl:call-template>
						</xsl:when>
						<xsl:when test="ancestor::grpform/head/heading[@sort=$sortorder]/@date">
							<xsl:call-template name="grpform-items">
								<xsl:with-param name="filtatt" select="$filteratt"/>
								<xsl:with-param name="filtval" select="$filterval"/>
								<xsl:with-param name="sorttyp">order-date-<xsl:value-of select="ancestor::grpform/head/heading[@sort=$sortorder]/@date"/></xsl:with-param>
								<xsl:with-param name="sortord" select="$sortorder"/>
							</xsl:call-template>
						</xsl:when>
						<xsl:when test="ancestor::grpform/head/heading[@sort=$sortorder]">
							<xsl:call-template name="grpform-items">
								<xsl:with-param name="filtatt" select="$filteratt"/>
								<xsl:with-param name="filtval" select="$filterval"/>
								<xsl:with-param name="sorttyp">order-name</xsl:with-param>
								<xsl:with-param name="sortord" select="$sortorder"/>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="grpform-items">
								<xsl:with-param name="filtatt" select="$filteratt"/>
								<xsl:with-param name="filtval" select="$filterval"/>
								<xsl:with-param name="sorttyp">order-defualt</xsl:with-param>
								<xsl:with-param name="sortord" select="$sortorder"/>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="grpform-items">
						<xsl:with-param name="filtatt" select="$filteratt"/>
						<xsl:with-param name="filtval" select="$filterval"/>
					</xsl:call-template>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test="$sortorder">
					<xsl:choose>
						<xsl:when test="ancestor::grpform/head/heading[@sort=$sortorder]/@number='yes'"><xsl:apply-templates select="item"><xsl:sort select="attribute::*[position()=number($sortorder)]" data-type="number"/></xsl:apply-templates></xsl:when>
						<xsl:when test="ancestor::grpform/head/heading[@sort=$sortorder]/@date='ascending'"><xsl:apply-templates select="item"><xsl:sort select="attribute::*[name()=$sortorder]" order="ascending"/></xsl:apply-templates></xsl:when>
						<xsl:when test="ancestor::grpform/head/heading[@sort=$sortorder]/@date='descending'"><xsl:apply-templates select="item"><xsl:sort select="attribute::*[name()=$sortorder]" order="descending"/></xsl:apply-templates></xsl:when>
						<xsl:when test="ancestor::grpform/head/heading[@sort=$sortorder]"><xsl:apply-templates select="item"><xsl:sort select="attribute::*[name()=$sortorder]"/></xsl:apply-templates></xsl:when>
						<xsl:otherwise><xsl:apply-templates select="item"><xsl:sort select="attribute::*[position()=number($sortorder)]"/></xsl:apply-templates></xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise><xsl:apply-templates select="item"/></xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template match="grpform/items/item">
	<xsl:call-template name="grpform-items-item"/>
</xsl:template>

<xsl:template name="grpform-items">
	<xsl:param name="filtatt"/>
	<xsl:param name="filtval"/>
	<xsl:param name="sorttyp"></xsl:param>
	<xsl:param name="sortord"></xsl:param>
	<!-- doesn't work: <xsl:apply-templates select="item[/attribute::*[text()=$filtval][name()=$filtatt]]"/>-->
	<xsl:comment>sorttyp:<xsl:value-of select="$sorttyp"/></xsl:comment>
	<xsl:comment>sortord:<xsl:value-of select="$sortord"/></xsl:comment>
	<xsl:choose>
		<xsl:when test="$sorttyp='order-name'">
			<xsl:for-each select="item">
				<xsl:sort select="attribute::*[name()=$sortord]"/>
				<xsl:variable name="thisatt" select="attribute::*[name()=$filtatt]"/>
				<xsl:comment>thisatt: '<xsl:value-of select="$thisatt"/>'</xsl:comment>
				<xsl:if test="$thisatt=$filtval">
					<xsl:call-template name="grpform-items-item"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:when>
		<xsl:when test="$sorttyp='order-number'">
			<xsl:for-each select="item">
				<xsl:sort select="attribute::*[position()=number($sortord)]" data-type="number"/>
				<xsl:variable name="thisatt" select="attribute::*[name()=$filtatt]"/>
				<xsl:comment>thisatt: '<xsl:value-of select="$thisatt"/>'</xsl:comment>
				<xsl:if test="$thisatt=$filtval">
					<xsl:call-template name="grpform-items-item"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:when>
		<xsl:when test="$sorttyp='order-date-ascending'">
			<xsl:for-each select="item">
				<xsl:sort select="attribute::*[name()=$sortord]" order="ascending"/>
				<xsl:variable name="thisatt" select="attribute::*[name()=$filtatt]"/>
				<xsl:comment>thisatt: '<xsl:value-of select="$thisatt"/>'</xsl:comment>
				<xsl:if test="$thisatt=$filtval">
					<xsl:call-template name="grpform-items-item"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:when>
		<xsl:when test="$sorttyp='order-date-descending'">
			<xsl:for-each select="item">
				<xsl:sort select="attribute::*[name()=$sortord]" order="descending"/>
				<xsl:variable name="thisatt" select="attribute::*[name()=$filtatt]"/>
				<xsl:comment>thisatt: '<xsl:value-of select="$thisatt"/>'</xsl:comment>
				<xsl:if test="$thisatt=$filtval">
					<xsl:call-template name="grpform-items-item"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:when>
		<xsl:when test="$sorttyp='order-default'">
			<xsl:for-each select="item">
				<xsl:sort select="attribute::*[position()=number($sortord)]"/>
				<xsl:variable name="thisatt" select="attribute::*[name()=$filtatt]"/>
				<xsl:comment>thisatt: '<xsl:value-of select="$thisatt"/>'</xsl:comment>
				<xsl:if test="$thisatt=$filtval">
					<xsl:call-template name="grpform-items-item"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:when>
		<xsl:otherwise>
			<xsl:for-each select="item">
				<xsl:variable name="thisatt" select="attribute::*[name()=$filtatt]"/>
				<xsl:comment>thisatt: '<xsl:value-of select="$thisatt"/>'</xsl:comment>
				<xsl:if test="$thisatt=$filtval">
					<xsl:call-template name="grpform-items-item"/>
				</xsl:if>
			</xsl:for-each>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="grpform-items-item">
	<xsl:variable name="grpformname"><xsl:value-of select="ancestor::grpform/@name"/></xsl:variable>
	<xsl:variable name="item" select="."/>
	<xsl:variable name="itemtext" select="text()"/>
	<xsl:variable name="itempos" select="position()"/>
	<tr>
		<xsl:attribute name="class">
			<xsl:choose>
				<xsl:when test="position() mod 2 = 1">grp_row_odd</xsl:when>
				<xsl:when test="position() mod 2 = 0">grp_row_even</xsl:when>
			</xsl:choose>
		</xsl:attribute>
		<!-- now get the order of the cells from the head elements... -->
		<xsl:for-each select="ancestor::grpform/head/heading[not(@visible='no')]">
			<td>
				<xsl:attribute name="class">
					<xsl:choose>
						<xsl:when test="@type='action-drop'">grp_cell_hdact</xsl:when>
						<xsl:when test="position()=1 or @format='left'">grp_cell_lft</xsl:when>
						<xsl:when test="@format='rand' or @format='percent'">grp_cell_rht</xsl:when>
						<xsl:otherwise>grp_cell</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				<xsl:if test="@size"><xsl:attribute name="width"><xsl:value-of select="@size"/></xsl:attribute></xsl:if>
				<!--
				<xsl:attribute name="width">
					<xsl:choose>
						<xsl:when test="@size"><xsl:value-of select="@size"/></xsl:when>
						<xsl:otherwise><xsl:text>*</xsl:text></xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
				-->
			 	<xsl:call-template name="grpform-item">
					<xsl:with-param name="thisname" select="$grpformname"/>
					<xsl:with-param name="thisitem" select="$item"/>
					<xsl:with-param name="thistext" select="$itemtext"/>
					<xsl:with-param name="thispos" select="$itempos"/>
				</xsl:call-template>
			</td>
		</xsl:for-each>
	</tr>
</xsl:template>

<xsl:template match="param">
</xsl:template>

<xsl:template match="nodata">
	<xsl:variable name="thisnum" select="ancestor::grpform/head/heading"/>
	<xsl:variable name="thistot" select="count($thisnum)"/>
	<tr>
		<td class="grp_cell">
			<xsl:attribute name="colspan"><xsl:value-of select="$thistot"/></xsl:attribute>
			<span class="grp_text">
				<xsl:choose>
					<xsl:when test="@prompt"><xsl:value-of select="@prompt"/></xsl:when>
					<xsl:otherwise>Sorry, no data available</xsl:otherwise>
				</xsl:choose>
			</span></td>
	</tr>
</xsl:template>


<!-- =======================
	 Named templates section
	 ======================= -->
	 
<xsl:template name="grpform-item">
	<xsl:param name="thisname"/>
	<xsl:param name="thisitem"/>
	<xsl:param name="thistext"/>
	<xsl:param name="thispos"/>

	<xsl:variable name="thisitem_id" select="@id"/>
	<!-- thisid is either the literal 'id' attribute of the item element or...
		... another attibute of the item element, identified by the 'id' attribute of the current 'heading' element -->
	<xsl:variable name="thisid">
		<xsl:choose>
			<xsl:when test="ids">
				<xsl:call-template name="grp-idval">
					<xsl:with-param name="thisitem" select="$thisitem"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="@id"><xsl:value-of select="$thisitem/attribute::*[name()=$thisitem_id]"/></xsl:when>
			<xsl:otherwise><xsl:value-of select='$thisitem/@id'/></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="thisattr" select="@name"/>
	<xsl:variable name="thisval" select="$thisitem/attribute::*[name()=$thisattr]"/>
	<xsl:choose>
		<xsl:when test="@type='action-drop'">
			<select>
				<xsl:attribute name='id'><xsl:value-of select='$thispos'/></xsl:attribute>
				<xsl:attribute name='name'>Drop_Go_<xsl:value-of select='$thispos'/></xsl:attribute>
				<xsl:for-each select='actions/action'>
					<option>
						<xsl:attribute name='value'>
							<xsl:call-template name="grpform-action">
								<xsl:with-param name="thisid"><xsl:value-of select='$thisid'/></xsl:with-param>
								<xsl:with-param name="thisitm" select="$thisitem"/>
							</xsl:call-template>
						</xsl:attribute>
						<xsl:choose>
							<xsl:when test="@label"><xsl:value-of select="@label"/></xsl:when>
							<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
						</xsl:choose>
					</option>
				</xsl:for-each>
			</select>
			<input type="button" value="GO" class="grp_btn">
				<xsl:attribute name="onclick">
					<xsl:text>javascript:x_grp.Go(Drop_Go_</xsl:text>
					<xsl:value-of select='$thispos'/>
					<xsl:text>);</xsl:text>
				</xsl:attribute>
			</input>
		</xsl:when>
		<xsl:when test="@type='item-enum'"><!-- similar to item-drop, but only referenced (eg the confirms of an item-drop) -->
			<span class="grp_text"><xsl:value-of select="subobjs/subwf_obj[value=$thisval]/prompt"/></span>
		</xsl:when>
		<xsl:when test="@type='item-filter'"><!-- similar to item-enum, but only referenced to a filter -->
			<xsl:variable name="thisfilt"><xsl:value-of select="@filtername"/></xsl:variable>
			<span class="grp_text"><xsl:value-of select="ancestor::grpform/filters/filter[@name=$thisfilt]/subobjs/subwf_obj[value=$thisval]/prompt"/></span>
		</xsl:when>
		<xsl:when test="@type='item-date'"><!-- expects datatime string eg: '2002-11-02T22:10:35.23' -->
			<span class="grp_text"><xsl:value-of select="substring-before($thisval, 'T')"/></span>
		</xsl:when>
		<xsl:when test="@type='item-time'"><!-- expects datatime string eg: '2002-11-02T22:10:35.23' -->
			<span class="grp_text"><xsl:value-of select="substring-after($thisval, 'T')"/></span>
		</xsl:when>
		<xsl:when test="@type='item-date-utc'"><!-- expects datatime string eg: '2002-11-02T22:10:35.2330000+02:00' -->
			<span class="grp_text"><xsl:value-of select="substring-before($thisval, 'T')"/></span>
		</xsl:when>
		<xsl:when test="@type='item-time-utc'"><!-- expects datatime string eg: '2002-11-02T22:10:35.2330000+02:00' -->
			<span class="grp_text"><xsl:value-of select="substring-before(substring-after($thisval, 'T'), '+')"/></span>
		</xsl:when>
		<xsl:when test="@type='value'">	<!-- value of the node -->
			<span class="grp_text"><xsl:value-of select="$thistext"/></span>
		</xsl:when>
		<xsl:otherwise>
			<xsl:choose>
				<xsl:when test="@type='item-add-multi'"><span class="grp_text"><xsl:value-of select="$thisval"/></span></xsl:when>
				<xsl:when test="@type='action'">
					<a>
						<xsl:attribute name="href">
							<xsl:for-each select="action"><!-- but only 1 -->
								<xsl:call-template name="grpform-action">
									<xsl:with-param name="thisid"><xsl:value-of select='$thisid'/></xsl:with-param>
									<xsl:with-param name="thisitm" select="$thisitem"/>
								</xsl:call-template>
							</xsl:for-each>
							<xsl:for-each select="param">
								<xsl:variable name="paramname" select="@name"/>
								<xsl:text>&amp;</xsl:text><xsl:value-of select="."/><xsl:text>=</xsl:text><xsl:value-of select="$thisitem/attribute::*[name()=$paramname]"/>
							</xsl:for-each>
						</xsl:attribute>
						<span class="grp_text"><xsl:value-of select="$thisval"/></span>
					</a>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="@format='rand'">
							<span class="grp_text">R<xsl:value-of select="format-number($thisval, '###,###.00')"/></span>
						</xsl:when>
						<xsl:when test="@format='integer'">
							<span class="grp_text"><xsl:number value="$thisval" format="1"/></span>
						</xsl:when>
						<xsl:when test="@format='percent'">
							<span class="grp_text"><xsl:value-of select="format-number($thisval, '###.0')"/>%</span>
						</xsl:when>
						<xsl:otherwise>
							<span class="grp_text"><xsl:value-of select="$thisval"/></span>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!--	ex original:

		<xsl:when test="@type='edit'">
			<input type='Text' size="15">
				<xsl:attribute name='id'>item_<xsl:value-of select='$thispos'/>_<xsl:value-of select='$thisattr'/></xsl:attribute>
				<xsl:attribute name='name'><xsl:value-of select='@name'/>_<xsl:value-of select='$thispos'/></xsl:attribute>
				<xsl:attribute name='value'><xsl:value-of select="$thisval"/></xsl:attribute>
			</input>
		</xsl:when>
		<xsl:when test="@type='item-query'">
			<xsl:call-template name="grpfrm-btn">
				<xsl:with-param name="thisid"><xsl:value-of select='$thisid'/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="@type='item-del' or @type='item-edit' or @type='item-go'">
			<xsl:call-template name="grpfrm-btn">
				<xsl:with-param name="thisid"><xsl:value-of select='$thisid'/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="@type='item-btn'">
			<xsl:variable name="thisact">
				<xsl:choose>
					<xsl:when test="@form">form</xsl:when>
					<xsl:when test="@service">serv</xsl:when>
					<xsl:otherwise>link</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname"><xsl:value-of select="@button"/></xsl:with-param>
				<xsl:with-param name="btnaction"><xsl:value-of select="$thisact"/></xsl:with-param>
				<xsl:with-param name="btnlink"><xsl:value-of select="@link"/></xsl:with-param>
				<xsl:with-param name="btnform"><xsl:value-of select="@form"/></xsl:with-param>
				<xsl:with-param name="btnservice"><xsl:value-of select="@service"/></xsl:with-param>
				<xsl:with-param name="btnprocess"><xsl:value-of select="@process"/></xsl:with-param>
				<xsl:with-param name="btnid"><xsl:value-of select="$thisid"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="@type='item-edit-multi'">
			<xsl:attribute name="class"><xsl:text>grp-msg-cell-inp</xsl:text></xsl:attribute>
			<input type="Checkbox">
				<xsl:attribute name="class"><xsl:value-of select="$rowclass"/></xsl:attribute>
				<xsl:attribute name='id'><xsl:value-of select='$thisid'/></xsl:attribute>
				<xsl:attribute name='name'>edit_<xsl:value-of select='$thisid'/></xsl:attribute>
			</input>
		</xsl:when>
		<xsl:when test="@type='item-del-multi'">
			<xsl:attribute name="class"><xsl:text>grp-msg-cell-inp</xsl:text></xsl:attribute>
			<input type="Checkbox">
				<xsl:attribute name="class"><xsl:value-of select="$rowclass"/></xsl:attribute>
				<xsl:attribute name='id'><xsl:value-of select='$thisid'/></xsl:attribute>
				<xsl:attribute name='name'>delete_<xsl:value-of select='$thisid'/></xsl:attribute>
			</input>
		</xsl:when>
		<xsl:when test="@type='item-check'">
			<xsl:attribute name="class"><xsl:text>grp-msg-cell-inp</xsl:text></xsl:attribute>
			<input type="Checkbox">
				<xsl:attribute name="class"><xsl:value-of select="$rowclass"/></xsl:attribute>
				<xsl:attribute name='id'><xsl:value-of select='$thisid'/></xsl:attribute>
				<xsl:attribute name='name'>item_<xsl:value-of select='$thispos'/></xsl:attribute>
				<xsl:if test="$thisval='yes'">
					<xsl:attribute name='checked'><xsl:text>true</xsl:text></xsl:attribute>
				</xsl:if>
			</input>
		</xsl:when>
		<xsl:when test="@type='item-drop-go'">
			<xsl:attribute name="class"><xsl:text>grp-msg-cell-inp</xsl:text></xsl:attribute>
			<xsl:choose>
				<xsl:when test="$thisval = ''"><span class="grp_text"><xsl:call-template name="nobrspace"/></span></xsl:when>
				<xsl:otherwise>
					<select>
						<xsl:attribute name='id'><xsl:value-of select='$thisid'/></xsl:attribute>
						<xsl:attribute name='name'>Drop_Go_<xsl:value-of select='$thisid'/></xsl:attribute>
						<xsl:for-each select='subobjs/subwf_obj[value &gt;= 0]'>
							<option>
								<xsl:attribute name='value'><xsl:value-of select='value'/></xsl:attribute>
								<xsl:if test="value=$thisval">
									<xsl:attribute name='selected'></xsl:attribute>
								</xsl:if>
								<xsl:value-of select='prompt'/>
							</option>
						</xsl:for-each>
					</select>
					<a>	<xsl:attribute name="href">
							<xsl:value-of select="$x_baseurl"/><xsl:value-of select="action/@link"/>
							<xsl:choose>
								<xsl:when test="@form">
									<xsl:text>&amp;form=</xsl:text>
									<xsl:value-of select="@form"/>
								</xsl:when>
								<xsl:when test="action/@type = 'service'">
									<xsl:text>&amp;service=</xsl:text>
									<xsl:value-of select="action/@name"/>
									<xsl:text>&amp;process=</xsl:text>
									<xsl:value-of select="action/@process"/>
								</xsl:when>
							</xsl:choose>
						</xsl:attribute>
						<img onMouseOver="this.style.cursor='hand'">
							<xsl:attribute name="src"><xsl:value-of select="$img_root"/><xsl:value-of select="$x_site//image[@type='btnGo']"/></xsl:attribute>
						</img></a>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
		<xsl:when test="@type='item-drop'">
			<xsl:attribute name="class"><xsl:text>grp-msg-cell-inp</xsl:text></xsl:attribute>
			<xsl:variable name="chkattr" select="check/@name"/>
			<xsl:variable name="chkval" select="number($thisitem/attribute::*[name()=$chkattr])"/>
			<xsl:choose>
				<xsl:when test="$thisval = ''"><span class="grp_text"><xsl:call-template name="nobrspace"/></span></xsl:when>
				<xsl:when test="$thisval &lt; 0">
					<span class="grp_text"><xsl:value-of select="subobjs/subwf_obj[value=$thisval]/prompt"/></span>
				</xsl:when>
				<xsl:otherwise>
					<xsl:choose>
						<xsl:when test="$chkval='NaN' or $chkval=0">
							<span class="grp_text"><xsl:value-of select="check/prompt"/></span>
						</xsl:when>
						<xsl:otherwise>
							<input type="Hidden" value=''>
								<xsl:attribute name='name'><xsl:text>change_</xsl:text><xsl:value-of select='$thisid'/></xsl:attribute>
							</input>
							<select>
								<xsl:attribute name='id'><xsl:value-of select='$thisid'/></xsl:attribute>
								<xsl:attribute name='name'><xsl:text>select_</xsl:text><xsl:value-of select='$thisid'/></xsl:attribute>
								<xsl:attribute name="onchange">
									<xsl:text>javascript:x_grp.Change(</xsl:text>
									<xsl:value-of select="$formname"/>.change_<xsl:value-of select="$thisid"/>
									<xsl:text>, this.value);</xsl:text>
								</xsl:attribute>
								<xsl:for-each select='subobjs/subwf_obj[value &gt;= 0]'>
									<option>
										<xsl:attribute name='value'><xsl:value-of select='value'/></xsl:attribute>
										<xsl:if test="value=$thisval">
											<xsl:attribute name='selected'></xsl:attribute>
										</xsl:if>
										<xsl:value-of select='prompt'/>
									</option>
								</xsl:for-each>
							</select>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
		<xsl:when test="@type='item-drop-values'">
			<xsl:attribute name="class"><xsl:text>grp-msg-cell-inp</xsl:text></xsl:attribute>
			<xsl:variable name="chkattr" select="check/@name"/>
			<xsl:variable name="chkval" select="number($thisitem/attribute::*[name()=$chkattr])"/>
			<xsl:choose>
				<xsl:when test="$thisval = ''"><span class="grp_text"><xsl:call-template name="nobrspace"/></span></xsl:when>
				<xsl:when test="$thisval &lt; 0">
					<span class="grp_text"><xsl:value-of select="subobjs/subwf_obj[value=$thisval]/prompt"/></span>
				</xsl:when>
				<xsl:otherwise>
						<xsl:choose>
							<xsl:when test="$chkval='NaN' or $chkval=0">
								<span class="grp_text"><xsl:value-of select="check/prompt"/></span>
							</xsl:when>
							<xsl:otherwise>
								<select>
									<xsl:attribute name='id'><xsl:value-of select='$thisid'/></xsl:attribute>
									<xsl:attribute name='name'>select_<xsl:value-of select='$thisid'/></xsl:attribute>
									<xsl:for-each select='subobjs/subwf_obj[value &gt;= 0]'>
										<xsl:variable name="subval" select="number(substring-after(prompt, 'R'))"/>
										<xsl:if test="$chkval &gt; $subval or value = 0">
											<option>
												<xsl:attribute name='value'><xsl:value-of select='value'/></xsl:attribute>
												<xsl:if test="value=$thisval">
													<xsl:attribute name='selected'></xsl:attribute>
												</xsl:if>
												<xsl:value-of select='prompt'/>
											</option>
										</xsl:if>
									</xsl:for-each>
								</select>
							</xsl:otherwise>
						</xsl:choose>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
-->

<xsl:template name="grpform-hidden">
	<input type="Hidden" name="xaction" value=""/>
	<input type="Hidden" name="SortOrder">
		<xsl:attribute name="value">
			<xsl:choose>
				<xsl:when test="@sortorder"><xsl:value-of select="@sortorder"/></xsl:when>
				<xsl:otherwise></xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
	</input>
	<!-- see note in x_page.cs re 'FilterVal' field...
	<input type="Hidden" name="FilterVal">
		<xsl:attribute name="value">
			<xsl:choose>
				<xsl:when test="@filterval"><xsl:value-of select="@filterval"/></xsl:when>
				<xsl:otherwise></xsl:otherwise>
			</xsl:choose>
		</xsl:attribute>
	</input>
	-->
</xsl:template>

<xsl:template name="grpform-action">
	<xsl:param name="thisid"/>
	<xsl:param name="thisitm"/>
	<xsl:choose>
		<xsl:when test="@type='popup'">
			<!--
			<xsl:variable name="link" select="@link"/>
			<xsl:variable name="this-link" select="//lnk[@name=$link][1]"/>
			-->
			<xsl:text>javascript:x_pop.External('</xsl:text>
			<xsl:choose>
				<xsl:when test="source/@siteurl"><xsl:value-of select="$x_siteurl"/><xsl:value-of select="source"/></xsl:when>
				<xsl:otherwise><xsl:text>http://</xsl:text><xsl:value-of select="source"/></xsl:otherwise>
			</xsl:choose>
			<xsl:for-each select="parameter">
				<xsl:variable name="profname" select="."/>
				<xsl:choose>
					<xsl:when test="position()=1"><xsl:text>?</xsl:text></xsl:when>
					<xsl:otherwise><xsl:text>&amp;</xsl:text></xsl:otherwise>
				</xsl:choose>
				<xsl:value-of select="@name"/><xsl:text>=</xsl:text>
				<xsl:choose>
					<xsl:when test="@type='profile'"><xsl:value-of select="$x_fields/fld[@name=$profname]/value"/></xsl:when>
					<xsl:when test="@type='item'">
						<xsl:variable name="thisname" select="@name"/>
						<xsl:value-of select="$thisitm/attribute::*[name()=$thisname]"/>
					</xsl:when>
					<xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
			<xsl:if test="$thisid!=''">
				<xsl:text>&amp;id=</xsl:text>
				<xsl:value-of select="$thisid"/>
			</xsl:if>
			<xsl:text>');</xsl:text>
		</xsl:when>
		<xsl:when test="@type='page'">
			<xsl:value-of select="$x_baseurl"/><xsl:value-of select="@link"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$x_baseurl"/><xsl:value-of select="@link"/>
			<xsl:text>&amp;type=</xsl:text>
			<xsl:value-of select="@type"/>
			<xsl:text>&amp;name=</xsl:text>
			<xsl:value-of select="@name"/>
			<xsl:text>&amp;process=</xsl:text>
			<xsl:value-of select="@process"/>
			<xsl:if test="$thisid!=''">
				<xsl:text>&amp;id=</xsl:text>
				<xsl:value-of select="$thisid"/>
			</xsl:if>
			<xsl:for-each select="parameter">
				<xsl:variable name="thisref" select="."/>
				<xsl:text>&amp;</xsl:text><xsl:value-of select="@name"/><xsl:text>=</xsl:text>
				<xsl:choose>
					<xsl:when test="@type='profile'"><xsl:value-of select="$x_fields/fld[@name=$thisref]/value"/></xsl:when>
					<xsl:when test="@type='item'"><xsl:value-of select="$thisitm/attribute::*[name()=$thisref]"/></xsl:when>
					<xsl:otherwise><xsl:value-of select="$thisref"/></xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="grp-btn-link">
	<xsl:param name="thisbtn"/>
	<xsl:param name="thisval"/>
	<a>
		<xsl:attribute name="href">
			<xsl:choose>
				<xsl:when test="@service">
					<xsl:value-of select='$x_baseurl'/>
					<xsl:value-of select='$x_linkname'/>
					<xsl:text>&amp;service=</xsl:text>
					<xsl:value-of select="@service"/>
					<xsl:text>&amp;process=</xsl:text>
					<xsl:value-of select="@process"/>
				</xsl:when>
				<xsl:when test="@form">
					<xsl:value-of select='$x_baseurl'/>
					<xsl:value-of select='$x_linkname'/>
					<xsl:text>&amp;form=</xsl:text>
					<xsl:value-of select="@form"/>
					<xsl:if test="$thisval">
						<xsl:text>&amp;</xsl:text><xsl:value-of select="@name"/><xsl:text>=</xsl:text>
						<xsl:value-of select="$thisval"/>
					</xsl:if>
				</xsl:when>
			</xsl:choose>
		</xsl:attribute>
		<xsl:call-template name="site-img">
			<xsl:with-param name="thisname"><xsl:value-of select="$thisbtn"/></xsl:with-param>
		</xsl:call-template>
	</a>
</xsl:template>

<xsl:template name="grp-idval">
	<xsl:param name="thisitem"/>
	<xsl:for-each select="ids/id">
		<xsl:variable name="thisitem_id" select="@name"/>
		<xsl:text>&amp;</xsl:text><xsl:value-of select="@name"/>=<xsl:value-of select="$thisitem/attribute::*[name()=$thisitem_id]"/>
	</xsl:for-each>
</xsl:template>

<xsl:template name="grpfrm-btn">
	<!-- NB the current context node is assumed to be head/heading -->
	<xsl:param name="thisid"/>
	<xsl:param name="thisidref"/>
	<xsl:variable name="thisbtn">
		<xsl:choose>
			<xsl:when test="@type='item-del-multi' or @type='item-del'">btnDel</xsl:when>
			<xsl:when test="@type='item-edit-multi' or @type='item-edit'">btnEdit</xsl:when>
			<xsl:when test="@type='item-add-multi' or @type='item-add' or @type='item-add-enum'">btnAdd</xsl:when>
			<xsl:when test="@type='item-go'">btnGo</xsl:when>
			<xsl:when test="@type='item-drop'">btnSubmit</xsl:when>
			<xsl:when test="@type='item-query'">btnQuery</xsl:when>
			<xsl:otherwise>Unknown</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="thisact">
		<xsl:choose>
			<xsl:when test="@form">form</xsl:when>
			<xsl:when test="@service">serv</xsl:when>
			<xsl:otherwise>link</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:choose>
		<xsl:when test="$thisact='link'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname"><xsl:value-of select="$thisbtn"/></xsl:with-param>
				<xsl:with-param name="btnaction"><xsl:value-of select="$thisact"/></xsl:with-param>
				<xsl:with-param name="btnlink"><xsl:value-of select="@link"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$thisact='form'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname"><xsl:value-of select="$thisbtn"/></xsl:with-param>
				<xsl:with-param name="btnaction"><xsl:value-of select="$thisact"/></xsl:with-param>
				<xsl:with-param name="btnlink"><xsl:value-of select="@link"/></xsl:with-param>
				<xsl:with-param name="btnform"><xsl:value-of select="@form"/></xsl:with-param>
				<xsl:with-param name="btnprocess"><xsl:value-of select="@process"/></xsl:with-param>
				<xsl:with-param name="btnid"><xsl:value-of select="$thisid"/></xsl:with-param>
				<xsl:with-param name="btnidref"><xsl:value-of select="$thisidref"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$thisact='serv'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname"><xsl:value-of select="$thisbtn"/></xsl:with-param>
				<xsl:with-param name="btnaction"><xsl:value-of select="$thisact"/></xsl:with-param>
				<xsl:with-param name="btnlink"><xsl:value-of select="@link"/></xsl:with-param>
				<xsl:with-param name="btnservice"><xsl:value-of select="@service"/></xsl:with-param>
				<xsl:with-param name="btnprocess"><xsl:value-of select="@process"/></xsl:with-param>
				<xsl:with-param name="btnid"><xsl:value-of select="$thisid"/></xsl:with-param>
				<xsl:with-param name="btnidref"><xsl:value-of select="$thisidref"/></xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname"><xsl:value-of select="$thisbtn"/></xsl:with-param>
				<xsl:with-param name="btnaction"><xsl:value-of select="$thisact"/></xsl:with-param>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="grpform-btns">
	<xsl:param name="which"/>
	<xsl:param name="docref"/>
	<!--<xsl:text>form-btns:</xsl:text><xsl:value-of select="$which"/>-->
	<xsl:choose>
		<xsl:when test="$which = 'go'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnGo</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'next'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnNext</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'back'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnBack</xsl:with-param>
				<xsl:with-param name="btnaction">back</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'back-next'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnBack</xsl:with-param>
				<xsl:with-param name="btnaction">back</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="nobrspace"/>
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnNext</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'back-reply'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnBack</xsl:with-param>
				<xsl:with-param name="btnaction">back</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="nobrspace"/>
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnReply</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'confirm'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnBack</xsl:with-param>
				<xsl:with-param name="btnaction">back</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnSubmit</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which='submit'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnSubmit</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'send'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnSend</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'search'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnSearch</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'edit'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnEdit</xsl:with-param>
				<xsl:with-param name="btnaction">edit</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'delete'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnDelete</xsl:with-param>
				<xsl:with-param name="btnaction">delete</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'cancel'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnCancel</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:when test="$which = 'validate'">
			<xsl:call-template name="grpform-btn">
				<xsl:with-param name="btnname">btnSubmit</xsl:with-param>
				<xsl:with-param name="btnaction">validate</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise> <!-- no button -->
			<span class="micro"><xsl:call-template name="nobrspace"/></span>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="grpform-btn">
	<xsl:param name="btnname"/>
	<xsl:param name="btnaction"/>
	<xsl:param name="btnlink"/>
	<xsl:param name="btnform"/>
	<xsl:param name="btnservice"/>
	<xsl:param name="btnprocess"/>
	<xsl:param name="btnid"/>
	<xsl:param name="btnidref"/>
	<xsl:variable name="thisname">
		<xsl:choose>
			<xsl:when test="ancestor-or-self::grpform/@name"><xsl:value-of select="ancestor-or-self::grpform/@name"/></xsl:when>
			<xsl:when test="ancestor-or-self::hierform/@name"><xsl:value-of select="ancestor-or-self::hierform/@name"/></xsl:when>
			<xsl:when test="ancestor-or-self::fields/@name"><xsl:value-of select="ancestor-or-self::fields/@name"/></xsl:when>
			<xsl:otherwise><xsl:text>x_form_group</xsl:text></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="thislink">
		<xsl:choose>
			<xsl:when test="$btnlink!=''"><xsl:value-of select="$btnlink"/></xsl:when>
			<xsl:otherwise><xsl:value-of select="$x_linkname"/></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="thisidref">
		<xsl:choose>
			<xsl:when test="$btnidref!=''"><xsl:value-of select="$btnidref"/></xsl:when>
			<xsl:otherwise>''</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<img onMouseOver="this.style.cursor='hand'">
		<xsl:attribute name="src"><xsl:value-of select="$img_root"/><xsl:value-of select="$x_site//image[@type=$btnname]"/></xsl:attribute>
		<xsl:if test="not($btnaction='search' or $btnaction='browse')">
			<xsl:attribute name="onclick">
				<xsl:choose>
					<xsl:when test="$btnaction='back'">javascript:x_frm.Previous()</xsl:when>
					<!-- doesn't work! <xsl:when test="parent::*[name()='grpform']">javascript:x_frm.Check(Manage_Users,false)</xsl:when>
						try (not tested) <xsl:when test="ancestor::grpform">javascript:x_frm.Check(Manage_Users,false)</xsl:when> -->
					<xsl:when test="$btnaction='link'">javascript:x_grp.Form(<xsl:value-of select="$thisname"/>, 'link', '<xsl:value-of select="$thislink"/>', '', '', '', '')</xsl:when>
					<xsl:when test="$btnaction='form'">javascript:x_grp.Form(<xsl:value-of select="$thisname"/>, 'form', '<xsl:value-of select="$thislink"/>', '<xsl:value-of select="$btnid"/>', '<xsl:value-of select="$btnform"/>', '<xsl:value-of select="$btnprocess"/>', <xsl:value-of select="$thisidref"/>)</xsl:when>
					<xsl:when test="$btnaction='serv'">javascript:x_grp.Form(<xsl:value-of select="$thisname"/>, 'serv', '<xsl:value-of select="$thislink"/>', '<xsl:value-of select="$btnid"/>', '<xsl:value-of select="$btnservice"/>', '<xsl:value-of select="$btnprocess"/>', <xsl:value-of select="$thisidref"/>)</xsl:when>
					<xsl:when test="$btnaction='validate'">javascript:ValidateForm_<xsl:value-of select="$thisname"/>(<xsl:value-of select="$thisname"/>)</xsl:when>
					<xsl:otherwise>javascript:x_grp.Submit(<xsl:value-of select="$thisname"/>)</xsl:otherwise>
				</xsl:choose>
			</xsl:attribute>
		</xsl:if>
	</img>
</xsl:template>


</xsl:stylesheet>